package org.jadedanha.dao;

import org.jadedanha.dao.*;
import org.jadedanha.model.*;
import java.sql.*;
import java.util.*;

public class JogoDao extends Dao {

    public Integer lastInsertedId;

    public void save( Jogo j ) throws SQLException {

        String sql = "INSERT INTO jogo (assunto) VALUES(?)";

        PreparedStatement stm = this.getConnection().prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);

        stm.setString(1, j.getAssunto() );
        stm.execute();


        ResultSet rskey = stm.getGeneratedKeys();
         
        if (rskey != null && rskey.next()) {
              this.setUltimo ( rskey.getInt(1) );
        }

        stm.close();
    }

    public void setUltimo( Integer last ) {
        this.lastInsertedId = last;
    }

    public Integer getUltimo() {
        return this.lastInsertedId;
    }
}
